package com.ph.finder.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.SuggestOracle;

public class CitySuggestOracle extends SuggestOracle {

	public boolean isDisplayStringHTML() {
		return true;
	}

	public void requestSuggestions(final SuggestOracle.Request req,
			final SuggestOracle.Callback callback) {
		PrecinctServiceAsync service = (PrecinctServiceAsync) GWT.create(PrecinctService.class);
		service.getCitySuggestions(req, new AsyncCallback<SuggestOracle.Response>() {

			@Override
			public void onSuccess(SuggestOracle.Response result) {
				if (result == null) {
					callback.onSuggestionsReady(req, new SuggestOracle.Response());
				} else {
					callback.onSuggestionsReady(req, result);
				}
			}

			@Override
			public void onFailure(Throwable caught) {
				callback.onSuggestionsReady(req, new SuggestOracle.Response());
			}

		});
	}
}